<template>
		<modal-container v-el:modal title="编辑" class="edit-modal">
		<form v-el:submitform @submit.prevent> 
			<div>
				<table class="table table-hover">
					<tbody>
							<tr>
								<td>机构编号</td>
								<td>
									<input type="text" class="form-control" :value="model.brhNo" disabled  name="brhId">
								</td>
							</tr>
							<tr>
								<td>商户编号</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtId" disabled  name="mchtId">
								</td>
							</tr>
							<tr>
								<td>微信账号</td>
								<td>
									<input type="text" class="form-control" :value="model.nickname"  name="nickname">
								</td>
							</tr>							
							<tr>
								<td>微信token</td>
								<td>
									<input type="text" class="form-control" :value="model.token"  name="wxtoken">
								</td>
							</tr>																																										<tr>
								<td>微信appsecret</td>
								<td>
									<input type="text" class="form-control" :value="model.appsecret"  name="appsecret">
								</td>
							</tr>																																					
							<tr>
								<td>微信类型</td>
								<td>
								  <select name="wechatType" id="" class="form-control">								  	
								  	<option :selected="model.wechatType==1">订阅号</option>
								  	<option :selected="model.wechatType==2">服务号</option>
								  </select>
								</td>
							</tr>																																								
							<tr>
								<td>微信url</td>
								<td>
									<input type="text" class="form-control" :value="model.url"  name="url">
								</td>
							</tr>								
							<tr>
								<td>公众号appid</td>
								<td>
								  <input type="text" class="form-control" :value="model.appid"  name="appid">				
								</td>
							</tr>																																				 		
					</tbody>
				</table>
			</div>
			<div class="modal-footer">
				<v-button type="submit" theme="primary" class="pull-left">确认</v-button>
				<v-button @click="hide">取消</v-button>
			</div>
		</form>
		</modal-container>	

</template>

<script>
	
	let serialize = require('form-serialize');
	 
	export default {
		props: {
			model: {
			  type: Object,
				default:{}
			}
		},
		data:()=>({
			collection: {
				role: []
			}			
		}),
		methods: {
			  init() {
					$(this.$els.modal).modal("show");
				},
		  	hide() {
					$(this.$els.modal).modal("hide");
				},
				_selected(roleId) {		
					return (roleId == this.model.roleId);    				
				},
		    reload() {
					this.$dispatch("table-reload");
				},					
				submit(data) {

					let self = this;
					
					self.$post({
						url: "/api/v1" + projectName_Url + "/wechat/mcht/upd.html",
						data
					}).then(response => {
						let data = {
							title: "操作提示",
							content: "编辑操作成功"
						}
						Midway.alert(data);
						self.hide();
						self.reload();
					}, response => {

					});					
				}
	 },
	 ready() {
		  let self = this;
		 
			$(this.$els.submitform).submit(function () {
				return false;
			});	
		 
			$(this.$els.submitform).validate({
				submitHandler: function () {
					let form = this.currentForm;
					$(form).find("input").each(function () {
						$(this).val($.trim($(this).val()));
					});
					let _data = serialize(form, {
						hash: true,
						disabled: true,
						empty: true						
					});
					_data.brhNoFlag =  _data.brhId;
					_data.mchtIdFlag = _data.mchtId;
				  self.submit(_data);

				},
				rules: {
					nickname: {
						required: true
					},
					wxtoken: {
						required: true
					},
					appsecret: {
						required: true
					},
					url: {
						required: true
					},
					appid: {
						required: true
					}
				},
				messages: {
					nickname: {
						required: "微信账号为必填项"
					},		
					wxtoken: {
						required: "微信token为必填项"						
					},
					appsecret: {
						required: "微信appsecret为必填项"
					},
					url: {
						required: "微信url为必填项"
					},
					appid: {
						required: "公众号appid为必填项"
					}
				}					

			});		 

	 }
}
</script>